package com.jxin.mall.weixin.service;

import com.jxin.mall.config.parent.BaseService;
import com.jxin.mall.entity.consts.HttpRspStatusEnum;
import com.jxin.mall.entity.entity.GlobalRsp;
import com.jxin.mall.middle.util.redis.RedisUtil;
import com.jxin.mall.weixin.domain.consts.RedisKeyConsts;
import com.jxin.mall.weixin.service.api.WxRedisKeyService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 微信服务提供外部查询redis中code的实现类
 * @author  蔡佳新
 * @version 1.0
 * @since   jdk 1.8
 */
@RestController
@Slf4j
public class WxRedisKeyServiceImpl extends BaseService implements WxRedisKeyService {
    @Resource(name = "strProtoRedisUtil")
    private RedisUtil strProtoRedisUtil;
    @Override
    public GlobalRsp<String> getMemberRegisterCodeByPhone(String phone) {
        try {
            final String registerCode = strProtoRedisUtil.get(RedisKeyConsts.REGISTER_PHONE + phone);
            if(StringUtils.isNotBlank(registerCode)){
               return createSuccessWithData(registerCode);
            }
        }catch (Exception e){
            log.error(e.getMessage(), e);
        }
        return createCustomWithData(HttpRspStatusEnum.HTTP_RES_CODE_201.getCode(),
                                    HttpRspStatusEnum.HTTP_RES_CODE_201.getName(),
                                    phone);
    }
}
